package com.yunxin.core.infra.persistence.repository.user;

import com.yunxin.core.domain.model.user.UserVisitorInfo;
import com.yunxin.core.domain.model.user.UserVisitorInfoRepository;
import com.yunxin.core.infra.persistence.converter.UserInfoConverter;
import com.yunxin.core.infra.persistence.entity.user.UserVisitorInfoDO;
import com.yunxin.core.infra.persistence.mapper.user.UserVisitorInfoExtendMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

/**
 * @author zero°
 * @since 2023-07-13
 */
@Repository
@RequiredArgsConstructor
public class UserVisitorInfoRepositoryImpl implements UserVisitorInfoRepository {

    private final UserVisitorInfoExtendMapper userVisitorInfoExtendMapper;

    private final UserInfoConverter userInfoConverter;

    @Override
    public boolean saveUserVisitorInfo(UserVisitorInfo userVisitorInfo) {
        UserVisitorInfoDO userVisitorInfoDO = userInfoConverter.formUserVisitorInfo(userVisitorInfo);
        int count = userVisitorInfoExtendMapper.insertSelective(userVisitorInfoDO);
        return count > 0;
    }

    @Override
    public Long getUserVisitorInfoIdByVisitorAndChannelPromotion(String visitorId, String channelPromotionCode) {
        return userVisitorInfoExtendMapper.getUserVisitorInfoIdByVisitorAndChannelPromotion(visitorId, channelPromotionCode);
    }
}
